﻿using Prism.Events;
using System;
using System.Windows;
using TuTu.Common.Enums;
using TuTu.Common.Events;

namespace TuTu.WpfApp.Views
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        private IEventAggregator _ea;
        public MainWindow(IEventAggregator ea)
        {
            this._ea = ea;
            InitializeComponent();
            this.Loaded += MainWindow_Loaded;
        }

        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            if (IsLoaded)
            {
                _ea.GetEvent<WindowActionEvent>().Subscribe(WindowAction);
            }            
        }

        public void WindowAction(string str)
        {
            bool b= Enum.TryParse(str,out WindowActionEnum WinEnum);
            if (b)
            {
                switch (WinEnum)
                {
                    case WindowActionEnum.DragMove:
                        this.DragMove();
                        break;
                    case WindowActionEnum.MinSize:
                        this.WindowState = WindowState.Minimized;
                        break;
                    case WindowActionEnum.MaxSize:
                        this.WindowState = WindowState.Maximized;
                        break;
                    case WindowActionEnum.Hide:
                        this.Hide();
                        break;
                    case WindowActionEnum.Close:
                        Application.Current.Shutdown();
                        break;
                    default:
                        break;
                }
            }
        }

        private void Page_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            this.DragMove();
        }
    }
}
